# From the CMake FAQ:
# <http://www.paraview.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F>

IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
  MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\".  Did you install the library?")
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")

FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
  if (EXISTS ${file} OR IS_SYMLINK ${file})
    MESSAGE(STATUS "Uninstalling \"${file}\"")
    EXEC_PROGRAM(
      "@CMAKE_COMMAND@" ARGS "-E remove \"${file}\""
      OUTPUT_VARIABLE rm_out
      RETURN_VALUE rm_retval
      )
    IF(NOT "${rm_retval}" STREQUAL 0)
      MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"")
    ENDIF(NOT "${rm_retval}" STREQUAL 0)
  endif (EXISTS ${file} OR IS_SYMLINK ${file})
ENDFOREACH(file)

foreach(file ${files})
  get_filename_component (path ${file} PATH)
  file (GLOB directory_files RELATIVE path "*")
  string (REGEX REPLACE ";" "" directory_files "${directory_files}")
  string (STRIP directory_files "${directory_files}")
  if ("${directory_files}" STREQUAL "" AND EXISTS ${path})
    message (STATUS "Removing empty directory ${path}")
    EXEC_PROGRAM(
      "@CMAKE_COMMAND@" ARGS "-E remove_directory \"${path}\""
      OUTPUT_VARIABLE rm_out
      RETURN_VALUE rm_retval
      )
  endif ("${directory_files}" STREQUAL "" AND EXISTS ${path})
endforeach(file)